    package com.mamlambo.article.simplecalc.test;  
      
    import android.test.ActivityInstrumentationTestCase2;  
    import android.widget.TextView;  
    import com.mamlambo.article.simplecalc.MainActivity;  
    import com.mamlambo.article.simplecalc.R;  
      
    public class MathValidation extends ActivityInstrumentationTestCase2<MainActivity> {  
      
       private TextView result;  
      
       public MathValidation() {  
           super ("com.mamlambo.article.simplecalc", MainActivity.class);  
       }  
      
       @Override  
       protected void setUp() throws Exception {  
           super.setUp();  
      
           MainActivity mainActivity = getActivity();  
      
           result = (TextView) mainActivity.findViewById(R.id.result);  
       }
       
       private static final String NUMBER_24 = "2 4 ENTER ";  
       private static final String NUMBER_74 = "7 4 ENTER ";  
       private static final String ADD_RESULT = "98";  
         
       public void testAddValues() {  
         
    	    sendKeys(NUMBER_24 + NUMBER_74 + "ENTER");    
         
          // get result  
          String mathResult = result.getText().toString();  
          assertTrue("Add result should be 98", mathResult.equals(ADD_RESULT));  
       } 
       private static final String NUMBER_5_DOT_5 = "5 . 5 ENTER";
       private static final String ADD_DECIMAL_RESULT = "79.5";
       
       public void testAddDecimalValues() {  
           sendKeys(NUMBER_5_DOT_5 + NUMBER_74 + "ENTER");  
      
           String mathResult = result.getText().toString();  
           assertTrue("Add result should be " + ADD_DECIMAL_RESULT + " but was "  
                   + mathResult, mathResult.equals(ADD_DECIMAL_RESULT));  
     } 
       
       
       private static final String MULTIPLY_RESULT = "1776";
       public void testMultiplyValues() {  
    	   sendKeys(NUMBER_24+NUMBER_74+ " DPAD_RIGHT ENTER");  
    	  
    	   String mathResult = result.getText().toString();  
    	   assertTrue("Multiply result should be " + MULTIPLY_RESULT + " but was "  
    	           + mathResult, mathResult.equals(MULTIPLY_RESULT));  
    	} 
       
       
    }  